package com.cow.controller;

import com.cow.service.OrderService;
import com.cow.service.ProductService;
import com.cow.util.general.CommonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/view")
public class OverViewController {

    @Autowired
    private ProductService productService;
    @Autowired
    private OrderService orderService;

    @GetMapping("/dataInfo")
    public CommonResult getDataInfo(){
        Map<String,Object> resultMap = new HashMap<>();
        Map<String, Object> productData = productService.productOverView();
        Map<String, Object> orderData = orderService.orderOverView();
        if(productData != null && !productData.isEmpty()){
            resultMap.putAll(productData);
        }
        if(orderData != null && !orderData.isEmpty()){
            resultMap.putAll(orderData);
        }
        return CommonResult.success("查询商品订单数据成功",resultMap);
    }

    @GetMapping("/order-chart-date")
    public CommonResult getOrderChartDate(String startTime, String endTime){
        Map<String,Object> resultMap = new HashMap<>();
        List<Map<String, Object>> ringData = orderService.selectProductTypeChart(startTime, endTime);
        List<Map<String, Object>> lineData = orderService.selectChartDate(startTime, endTime);
        Map<String, Object> countData = orderService.selectCountAndAmount(startTime, endTime);
        if (ringData != null && !ringData.isEmpty()){
            resultMap.put("ringData", ringData);
        }
        if (lineData != null && !lineData.isEmpty()){
            resultMap.put("lineData", lineData);
        }
        if (countData != null && !countData.isEmpty()){
            resultMap.put("countData", countData);
        }
        return CommonResult.success("图表数据查询成功",resultMap);
    }
}
